package org.richin.web.struts.util;

import java.util.Collection;
import java.util.LinkedHashSet;
import java.util.Set;

import org.apache.commons.beanutils.Converter;
import org.hibernate.collection.PersistentSet;

import com.sun.org.apache.bcel.internal.generic.NEW;

public class PersistentSetConverter implements Converter {

	public Object convert(Class type, Object value) {
		if (value instanceof PersistentSet) {
			PersistentSet set = (PersistentSet) value;
			return new LinkedHashSet(set);
		}
		else if (value instanceof Collection) {
			LinkedHashSet set = (LinkedHashSet) value;
			PersistentSet persistentSet = new PersistentSet();
			persistentSet.addAll(set);
			return persistentSet;
		}
		else
			return value;
	}

}
